package com.yeqian.user.controller;

import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.yeqian.entity.ResultJson;
import com.yeqian.user.service.UserInfoService;
import com.yeqian.vo.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户管理控制器
 */
@Slf4j
@Api(tags = "用户管理")
@ApiSupport(order = 1)
@RestController
@RequestMapping(Urls.UserInfo.USER_INFO)
public class UserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @PreAuthorize("hasRole('admin')")
    @ApiOperation("分页查询用户列表")
    @PostMapping(Urls.UserInfo.LIST_USERINFO)
    public ResultJson listUserInfo(@RequestBody PageVO pageVO) {
        PageInfo<Map<String,Object>> list = userInfoService.listUserInfo(pageVO);
        return ResultJson.Success("查看用户列表成功", list);
    }

    @ApiOperation("查询个人B站信息")
    @PostMapping(Urls.UserInfo.GET_BILIBILI_INFO)
    public ResultJson getBilibiliInfo(@RequestParam(defaultValue = "90977264") String mid) {
        Map<String,Object> biliInfo=userInfoService.getBilibiliInfo(mid);
        return ResultJson.Success("查看b站个人信息成功", biliInfo);
    }


}
